package com.starry.module.system.core.tenant.controller.admin;

import cn.hutool.http.HttpStatus;
import com.starry.core.common.domain.R;
import com.starry.core.common.domain.vo.PageVo;
import com.starry.core.web.core.controller.BaseController;
import com.starry.module.system.api.tenant.domain.qo.SysTenantPackagePageQo;
import com.starry.module.system.api.tenant.domain.qo.SysTenantPackageQo;
import com.starry.module.system.api.tenant.domain.vo.SysTenantPackageDtlVo;
import com.starry.module.system.api.tenant.domain.vo.SysTenantPackageVo;
import com.starry.module.system.core.tenant.service.SysTenantPackageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 系统租户套餐
 *
 * @author xiaoke
 */
@Tag(name = "系统租户套餐")
@RestController
@RequestMapping("/system/sysTenantPackage")
public class SysTenantPackageController extends BaseController {

    private final SysTenantPackageService sysTenantPackageService;

    public SysTenantPackageController(SysTenantPackageService sysTenantPackageService) {
        this.sysTenantPackageService = sysTenantPackageService;
    }

    /**
     * 分页查询
     *
     * @param pageQo 查询实体
     * @return 所有数据
     */
    @Operation(summary = "系统租户套餐-分页查询")
    @GetMapping("sysTenantPackagePage")
    public R<PageVo<SysTenantPackageVo>> findPage(SysTenantPackagePageQo pageQo) {
        return success(this.sysTenantPackageService.page(pageQo));
    }

    /**
     * 下拉列表
     *
     * @param pageQo 查询实体
     * @return 所有数据
     */
    @Operation(summary = "系统租户套餐-下拉列表")
    @GetMapping("sysTenantPackageList")
    public R<List<SysTenantPackageVo>> findList(SysTenantPackagePageQo pageQo) {
        return success(this.sysTenantPackageService.list(pageQo));
    }

    /**
     * 详情
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(summary = "系统租户套餐-详情")
    @GetMapping("sysTenantPackageDetails/{id}")
    public R<SysTenantPackageDtlVo> findById(@PathVariable("id") Long id) {
        return success(this.sysTenantPackageService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysTenantPackageQo 实体对象
     * @return 新增结果
     */
    @Operation(summary = "系统租户套餐-新增")
    @PostMapping("sysTenantPackageCreate")
    public R<Long> insert(@RequestBody @Validated SysTenantPackageQo sysTenantPackageQo) {
        return success(HttpStatus.HTTP_CREATED, this.sysTenantPackageService.save(sysTenantPackageQo));
    }

    /**
     * 修改数据
     *
     * @param sysTenantPackageQo 实体对象
     * @return 修改结果
     */
    @Operation(summary = "系统租户套餐-修改")
    @PostMapping("sysTenantPackageUpdate")
    public R<Void> update(@RequestBody @Validated SysTenantPackageQo sysTenantPackageQo) {
        this.sysTenantPackageService.updateById(sysTenantPackageQo);
        return success();
    }

    /**
     * 删除数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统租户套餐-删除")
    @PostMapping("sysTenantPackageRemove")
    public R<Void> delete(@RequestParam("idList") Set<Long> idList) {
        this.sysTenantPackageService.removeByIds(idList);
        return success();
    }

    /**
     * 启用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统租户套餐-启用")
    @PostMapping("sysTenantPackageEnable")
    public R<Void> enable(@RequestParam("idList") Set<Long> idList) {
        this.sysTenantPackageService.enable(idList);
        return success();
    }

    /**
     * 禁用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "系统租户套餐-禁用")
    @PostMapping("sysTenantPackageDisable")
    public R<Void> disable(@RequestParam("idList") Set<Long> idList) {
        this.sysTenantPackageService.disable(idList);
        return success();
    }
}

